package com.qifenqian.turbot.module.presenter

import android.content.Context

import com.qifenqian.turbot.base.BasePresenter
import com.qifenqian.turbot.module.contract.CommentContract
import com.qifenqian.turbot.module.entity.response.CommentEntity
import com.qifenqian.turbot.module.model.CommentModel
import com.qifenqian.turbot.net.ModelCallback

/**
 * @author H
 * @createTime 2018/12/28 14:06
 * @description
 * @see
 * @since
 */
class CommentPresenter(context: Context, view: CommentContract.View) : BasePresenter<CommentContract.View, CommentModel>(context, view), CommentContract.Presenter {

    override fun reply(commentId: Int, replyContent: String, replyUserCode: String) {
        mModel.reply(commentId, replyContent, replyUserCode, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.replyResult(true)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.replyResult(false, code, msg)
            }
        })
    }

    override fun createModel(): CommentModel {
        return CommentModel(mContext)
    }

    override fun getCommentList(page: Int) {
        mModel.getCommentList(page, object : ModelCallback<List<CommentEntity>> {
            override fun onSuccess(msg: String?, t: List<CommentEntity>?) {
                mView?.getCommentListResult(true, commentEntities = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getCommentListResult(false, code, msg)
            }
        })
    }
}
